{% extends 'base.html' %}
{% load static %}
{% load sizeformat %}
{% load percentageformat %}

{% block title %}资源统计列表{% endblock %}

{% block head %}{% endblock %}

{% block boby %}
    <div class="container-fluid col-lg-12">
        <p class="h3">资源分配统计</p>
        <div class="card border-info">
            <div class="card-header">
                <h3 class="card-title">分中心</h3>
            </div>
            <table class="table">
                <thead class="thead-light">
                <tr>
                    <th>分中心</th>
                    <th>总物理cpu(/核)</th>
                    <th>总虚拟cpu(/核)</th>
                    <th>已分配cpu(/核)</th>
                    <th>cpu分配率</th>
                    <th>总内存</th>
                    <th>已使用内存</th>
                    <th>内存使用率</th>
                    <th>云主机数</th>
                </tr>
                </thead>
                <tbody>
                {% for c in centers %}
                    <tr>
                        <td><a href="{% url 'reports:reports-center' id=c.id %}">{{c.name}}</a></td>
                        <td>{{c.real_cpu}}</td>
                        <td>{{c.vcpu_total}}</td>
                        <td>{{c.vcpu_allocated}}</td>
                        <td>{{c.vcpu_allocated | percentageformat:c.vcpu_total}}</td>
                        <td>{{c.mem_total | sizeformat:'MB'}}</td>
                        <td>{{c.mem_allocated | sizeformat:'MB'}}</td>
                        <td>{{c.mem_allocated | percentageformat:c.mem_total}}</td>
                        <td>{{c.vm_created}}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <div class="card border-danger">
            <div class="card-header">
                <h3 class="card-title">宿主机组</h3>
            </div>
            <table class="table">
                <thead class="thead-light">
                <tr>
                    <th>宿主机组</th>
                    <th>分中心</th>
                    <th>总物理cpu(/核)</th>
                    <th>总虚拟cpu(/核)</th>
                    <th>已分配cpu(/核)</th>
                    <th>cpu分配率</th>
                    <th>总内存</th>
                    <th>已使用内存</th>
                    <th>内存使用率</th>
                    <th>云主机数</th>
                </tr>
                </thead>
                <tbody>
                {% for c in groups %}
                    <tr>
                        <td><a href="{% url 'reports:reports-group' id=c.id %}">{{c.name}}</a></td>
                        <td>{{c.center__name}}</td>
                        <td>{{c.real_cpu}}</td>
                        <td>{{c.vcpu_total}}</td>
                        <td>{{c.vcpu_allocated}}</td>
                        <td>{{c.vcpu_allocated | percentageformat:c.vcpu_total}}</td>
                        <td>{{c.mem_total | sizeformat:'MB'}}</td>
                        <td>{{c.mem_allocated | sizeformat:'MB'}}</td>
                        <td>{{c.mem_allocated | percentageformat:c.mem_total}}</td>
                        <td>{{c.vm_created}}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        <div class="card border-success">
            <div class="card-header">
                <h3 class="card-title">宿主机</h3>
            </div>
            <table class="table">
                <thead class="thead-light">
                <tr>
                    <th>宿主机IP</th>
                    <th>机组</th>
                    <th>物理cpu(/核)</th>
                    <th>虚拟cpu(/核)</th>
                    <th>已分配cpu(/核)</th>
                    <th>cpu分配率</th>
                    <th>总内存</th>
                    <th>已使用内存</th>
                    <th>内存使用率</th>
                    <th>云主机数</th>
                </tr>
                </thead>
                <tbody>
                {% for c in hosts %}
                    <tr>
                        <td>{{c.ipv4}}</td>
                        <td>{{c.group__name}}</td>
                        <td>{{c.real_cpu}}</td>
                        <td>{{c.vcpu_total}}</td>
                        <td>{{c.vcpu_allocated}}</td>
                        <td>{{c.vcpu_allocated | percentageformat:c.vcpu_total}}</td>
                        <td>{{c.mem_total | sizeformat:'MB'}}</td>
                        <td>{{c.mem_allocated | sizeformat:'MB'}}</td>
                        <td>{{c.mem_allocated | percentageformat:c.mem_total}}</td>
                        <td>{{c.vm_created}}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script>
        $("#nav_reports").addClass("active");
    </script>
{% endblock %}
